<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0 auto;
            text-align: center;
        }
    </style>
</head>

<body onload="rnd(0,255)">
    <div>
        <br>
        <br>
        <button onclick="push()">push入栈</button>
        <input id="inp" type="text">
        <button onclick="pop()">pop出栈</button>
        <br>
        <div id="show">
            
        </div>
        <br>
        <button onclick="name_()">随机点名</button>
        <div id="color" style="width: 100px;height: 100px"></div>
</body>
<script>
    //入栈和出栈
    var inp_ = document.getElementById("inp")
    var arr = new Array(3)
    arr[0] = "姓名"
    arr[1] = "性别"
    arr[2] = "年龄"
    function push() {
        document.getElementById("show").innerHTML=(arr.push(inp_.value)); 
        document.getElementById("show").innerHTML= arr;
    }
    function pop(){
        document.getElementById("show").innerHTML=(arr.pop(inp_.value)); 
        document.getElementById("show").innerHTML= arr;
    }
    //随机点名
    function name_(){
        var rng = ['白','张','王','李','赵']
        var a = Math.floor(Math.random()*5 + 1);
        switch(a)
            {
            case 1:
            document.getElementById("show").innerHTML = rng[1];
            break;
            case 2:
            document.getElementById("show").innerHTML = rng[2];
            break;
            case 3:
            document.getElementById("show").innerHTML = rng[3];
            break;
            case 4:
            document.getElementById("show").innerHTML = rng[4];
            break;
            case 5:
            document.getElementById("show").innerHTML = rng[5];
            break;
            default:
            }
    }
    //随机颜色
    function rnd(n, m) {
        var random_1 = Math.floor(Math.random() * (m - n + 1) + n);
        var random_2 = Math.floor(Math.random() * (m - n + 1) + n);
        var random_3 = Math.floor(Math.random() * (m - n + 1) + n);
        // var dd = "<div class='a1'style='background-color: rgb(" + random_1 + "," + random_2 "," + random_3 + ");'>xx</div>"
        var dd = '<div class="a1" style="background-color:rgb(' + random_1 + ',' + random_2 + ',' + random_3 + ');width: 100px;height: 100px;"></div>';
        document.getElementById("color").innerHTML = dd;

    }
    
</script>

</html>